package com.daidai.controller;

import com.daidai.domain.Common;
import com.daidai.domain.Customer;
import com.daidai.service.customer.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("customer")
public class CustomerController {

    @Autowired
    CustomerServiceImpl customerService;

    @GetMapping("getAll")
    public Common getAllCus() {
        return customerService.getAllCus();
    }

    @GetMapping("getNoAll")
    public Common getNoAllCus() {
        return customerService.getNoCus();
    }

    @GetMapping("getIsDel")
    public Common getIsDel() {
        return customerService.getIsDel();
    }

    @GetMapping("getByTel/{tel}")
    public Common getCusByTel(@PathVariable Long tel) {
        return customerService.getCusByParam("telnum", tel);
    }

    @GetMapping("getById/{id}")
    public Common getCusById(@PathVariable Long id) {
        return customerService.getCusByParam("cid", id);
    }

    @PostMapping("regCus")
    public Common regCus(@RequestBody Customer customer) {
        if (customerService.RegCus(customer)) {
            return Common.success("注册成功");
        }
        return Common.error(500, "注册失败");
    }

    @DeleteMapping("delCus/{id}")
    public Common delCus(@PathVariable int id) {
        return customerService.delCus(id);
    }

    @PostMapping("update")
    public Common updateCus(@RequestBody Customer customer) {
        return customerService.updateCus(customer);
    }

}
